package mt.filter;

import static org.junit.Assert.assertNotNull;

import java.util.ArrayList;

import mt.Order;
import mt.comm.ServerComm;
import mt.comm.ServerSideMessage;
import mt.comm.ServerSideMessage.Type;


import Network.MicroTraderServerNetwork;
import Network.ServerCommunication;
import Network.ServerSideMsg;
import mt.server.MicroTraderServer;

import org.junit.Test;

public class AnalyticsFilterTest {

	/**
	 * Test method for {@link mt.filter.AnalyticsFilter#getNextMessage()}.
	 */

	@Test
	public void testGetNextMessage() {
		//Codigo apenas para testes a partir do main
		ServerCommunication serverComm = new ServerCommunication();
		serverComm.start();
		//data generation
		ArrayList<ServerSideMessage> messageList=new ArrayList<ServerSideMessage>();
		Order order = null;
		System.out.println("Server CommDummyStarted");

		for (int i=0;i<20;i++){
			ServerSideMsg message = new ServerSideMsg (Type.DISCONNECTED,("mailClient"+i+"@mail.mail"),null);
			messageList.add(message);

		}
		for (int i=0;i<20;i++){
			ServerSideMsg message = new ServerSideMsg (Type.CONNECTED,("mailClient"+i+"@mail.mail"),null);
			messageList.add(message);

		}

		for (int i=10;i<20;i++){
			String nickname = ("mailClient"+i+"@mail.mail");
			Order order1=order.createBuyOrder(nickname, "xpto", 10, 200.0);
			ServerSideMsg message = new ServerSideMsg (Type.NEW_ORDER,nickname,order1);
			System.out.println(message.getOrder().toString());
			messageList.add(message);

		}
		for (int i=10;i<20;i++){
			String nickname = ("mailClient"+i+"@mail.mail");
			Order order2=order.createSellOrder(nickname, "xpto", 10, 200.0);
			ServerSideMsg message = new ServerSideMsg (Type.NEW_ORDER,nickname,order2);
			System.out.println(message.getOrder().toString());
			messageList.add(message);

		}
		for (int i=10;i<20;i++){
			String nickname = ("mailClient"+i+"@mail.mail");
			Order order2=order.createSellOrder(nickname, "xpto", 10, 200.0);
			ServerSideMsg message = new ServerSideMsg(Type.NEW_ORDER,nickname,order2);
			System.out.println(message.getOrder().toString());
			messageList.add(message);

		}
		for (int i=10;i<20;i++){
			String nickname = ("mailClient"+i+"@mail.mail");
			Order order2=order.createSellOrder(nickname, "xpto", 10, 200.0);
			ServerSideMsg message = new ServerSideMsg (Type.NEW_ORDER,nickname,order2);
			System.out.println(message.getOrder().toString());
			messageList.add(message);

		}
		for (int i=10;i<20;i++){
			ServerSideMsg message = new ServerSideMsg (Type.CONNECTED,("mailClient"+i+"@mail.mail"),null);
			messageList.add(message);

		}
		assertNotNull(messageList);
		assertNotNull(serverComm);
		serverComm.loadDataForTesting(messageList);
		AnalyticsFilter filter = new AnalyticsFilter(serverComm);
		MicroTraderServer  server = new MicroTraderServerNetwork();
		assertNotNull(filter);
		assertNotNull(server);
		server.start(filter);



	}

}
